package com.example.ctcdemo.entity;

/**
 * @Description 包装工具类
 * @Auther chongling guo
 * @Date 2021-07-23 17:18
 **/
public class ResultUtil {

    public static <T> Result<T>  success(T data, String msg) {
        Result result = new Result<>();
        result.setMsg(msg).setData(data).setCode(RetCode.SUCCESS.code);
        return result;
    }

    public static <T> Result<T> unAuthorized() {
        Result result = new Result<>();
        result.setMsg("暂无权限");
        result.setData(null).setCode(RetCode.UNAUTHORIZED.code);
        return result;
    }

    public static <T> Result<T> serverError() {
        Result result = new Result<>();
        result.setMsg("服务器错误");
        result.setData(null).setCode(RetCode.SERVER_ERROR.code);
        return result;
    }

    public static <T> Result<T> requestError(){
        Result result = new Result<>();
        result.setMsg("请求有误");
        result.setData(null).setCode(RetCode.REQUEST_ERROR.code);
        return result;
    }

    public static <T> Result<T> tokenError(){
        Result result = new Result<>();
        result.setMsg("Token异常");
        result.setData(null).setCode(RetCode.Token_ERROR.code);
        return result;
    }

    public static <T> Result<T> define(int code, String msg, T data){
        Result result = new Result();
        result.setCode(code).setMsg(msg).setData(data);
        return result;
    }

}
